package com.isoftstone.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.isoftstone.dao.DocDao;
import com.isoftstone.entity.CK_Prescription;
import com.isoftstone.entity.C_Medicine;
import com.isoftstone.entity.C_Prescription;
import com.isoftstone.entity.Inpesction_item;
import com.isoftstone.entity.Patient;
import com.isoftstone.entity.Register;
import com.isoftstone.entity.Users;
import com.isoftstone.entity.W_Medicine;
import com.isoftstone.entity.W_Prescription;
import com.isoftstone.service.DocService;
@Service
public class DocServiceImpl implements DocService {
	
	@Autowired
	private DocDao dao;
	@Override
	public List<Patient> getAllpatient() {
		// TODO Auto-generated method stub
		List<Patient> list=dao.getAllpatient();
		return list;
	}
	@Override
	public List<C_Medicine> getAllCM() {
		// TODO Auto-generated method stub
		List<C_Medicine> c_medicine=dao.getAllCM();
		
		return c_medicine;
	}
	@Override
	public Patient getpatientById(String guahao_id) {
		// TODO Auto-generated method stub
		String card_id =dao.getCard_id(guahao_id);
		Patient patient= dao.getpatientById(card_id);
		return patient;
	}
	@Override
	public boolean insertCM(String guahao_id,String cm_id,int cm_num) {
		// TODO Auto-generated method stub
		C_Medicine c_medicine=dao.getCMById(cm_id);
		System.out.println(c_medicine);
		String cm_name=c_medicine.getCm_name();
		String cm_usage=c_medicine.getCm_dosage();
		Double cm_price=c_medicine.getCm_price();
		
		Double cm_amount=cm_price*cm_num;
		boolean flag = dao.insertCM(cm_id,cm_name,cm_usage,guahao_id,cm_price,cm_num,cm_amount);
		return flag;
	}
	@Override
	public Register getRegisterById(String guahao_id) {
		// TODO Auto-generated method stub
		Register register=dao.getRegisterById(guahao_id);
		return register;
	}
	@Override
	public List<C_Prescription> getAllCPById(String guahao_id) {
		// TODO Auto-generated method stub
		
		return dao.getAllCPById(guahao_id);
	}
	@Override
	public C_Prescription getCMYizhu(String guahao_id, String cm_id) {
		// TODO Auto-generated method stub
		if(guahao_id!=null||cm_id!=null){
			C_Prescription c_prescription=dao.getCMYizhu(guahao_id,cm_id);
			return c_prescription;
		}
		
		return null;
	}
	@Override
	public boolean updateCMYizhu(String guahao_id, String cm_id, String cm_yizhu) {
		// TODO Auto-generated method stub
		boolean flag=dao.updateCMYizhu(guahao_id,cm_id,cm_yizhu);
		return flag;
	}
	
	@Override
	public List<W_Medicine> getAllWM() {
		// TODO Auto-generated method stub
		List<W_Medicine> w_medicine=dao.getAllWM();
		
		return w_medicine;
		
	}
	@Override
	public List<W_Prescription> getAllWPById(String guahao_id) {
		// TODO Auto-generated method stub
		return dao.getAllWPById(guahao_id);
		
	}
	@Override
	public boolean insertWM(String guahao_id, String wm_id,int wm_num) {
		// TODO Auto-generated method stub
		W_Medicine w_medicine=dao.getWMById(wm_id);
		System.out.println(w_medicine);
		String wm_name=w_medicine.getWm_name();
		String wm_usage=w_medicine.getWm_dosage();
		Double wm_price=w_medicine.getWm_price();
		
		Double wm_amount=wm_price*wm_num;
		boolean flag = dao.insertWM(wm_id,wm_name,wm_usage,guahao_id,wm_price,wm_num,wm_amount);
		return flag;
	}
	@Override
	public W_Prescription getWMYizhu(String guahao_id, String wm_id) {
		// TODO Auto-generated method stub
		if(guahao_id!=null||wm_id!=null){
			W_Prescription w_prescription=dao.getWMYizhu(guahao_id,wm_id);
			return w_prescription;
		}
		
		return null;
	}
	@Override
	public boolean updateWMYizhu(String guahao_id, String wm_id, String wm_yizhu) {
		// TODO Auto-generated method stub
		boolean flag=dao.updateWMYizhu(guahao_id,wm_id,wm_yizhu);
		return flag;
	}
	@Override
	public boolean deleteCM(String guahao_id, String cm_id) {
		// TODO Auto-generated method stub
		boolean flag = dao.deleteCM(guahao_id,cm_id);
		return flag;
	}
	@Override
	public boolean deleteWM(String guahao_id, String wm_id) {
		// TODO Auto-generated method stub
		boolean flag = dao.deleteWM(guahao_id,wm_id);
		return flag;
	}
	@Override
	public List<C_Medicine> searchCM(String cm_name) {
		// TODO Auto-generated method stub
		
		List<C_Medicine> c_medicine=dao.searchCM(cm_name);
		return c_medicine;
	}
	@Override
	public List<W_Medicine> searchWM(String wm_name) {
		// TODO Auto-generated method stub
		
		List<W_Medicine> w_medicine=dao.searchWM(wm_name);
		return w_medicine;
	}

	@Override
	public List<Inpesction_item> getAllCK() {
		// TODO Auto-generated method stub
		List<Inpesction_item> inpesction_item=dao.getAllCK();
		
		return inpesction_item;
		
	}
	@Override
	public List<CK_Prescription> getAllCKById(String guahao_id) {
		// TODO Auto-generated method stub
		return dao.getAllCKById(guahao_id);
		
	}
	@Override
	public boolean insertCK(String guahao_id, String ii_id,int ii_num) {
		// TODO Auto-generated method stub
		Inpesction_item ii=dao.getCKById(ii_id);
		System.out.println(ii);
		String ck_name=ii.getIi_name();
		String ck_dept=ii.getIi_dept();
		Double ck_price=ii.getIi_price();
		int ck_num=ii_num;
		Double ck_amount=ck_price*ck_num;
		boolean flag = dao.insertCK(ii_id,ck_name,ck_dept,guahao_id,ck_price,ck_num,ck_amount);
		return flag;
	}
	@Override
	public CK_Prescription getCKYizhu(String guahao_id, String ck_id) {
		// TODO Auto-generated method stub
		if(guahao_id!=null||ck_id!=null){
			CK_Prescription ck_prescription=dao.getCKYizhu(guahao_id,ck_id);
			return ck_prescription;
		}
		
		return null;
	}
	@Override
	public boolean updateCKYizhu(String guahao_id, String ck_id, String ck_yizhu) {
		// TODO Auto-generated method stub
		boolean flag=dao.updateCKYizhu(guahao_id,ck_id,ck_yizhu);
		return flag;
	}
	@Override
	public boolean deleteCK(String guahao_id, String ck_id) {
		// TODO Auto-generated method stub
		boolean flag = dao.deleteCK(guahao_id,ck_id);
		return flag;
	}
	@Override
	public List<Inpesction_item> searchCK(String ii_name) {
		// TODO Auto-generated method stub
		
		List<Inpesction_item> inpesction_item=dao.searchCK(ii_name);
		return inpesction_item;
	}
}
